<html>
<head><meta charset="utf-8"><title>Path::from_src · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Path.3A.3Afrom_src.html">Path::from_src</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="183770637"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Path%3A%3Afrom_src/near/183770637" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Path.3A.3Afrom_src.html#183770637">(Dec 18 2019 at 17:25)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> Do you think now is a good time/idea to change </p>
<div class="codehilite"><pre><span></span><span class="k">fn</span> <span class="nf">Path</span>::<span class="n">from_src</span><span class="p">(</span><span class="n">path</span>: <span class="nc">ast</span>::<span class="n">Path</span><span class="p">,</span><span class="w"> </span><span class="n">hygiene</span>: <span class="kp">&amp;</span><span class="nc">Hygiene</span><span class="p">)</span><span class="w"></span>
</pre></div>


<p>to</p>
<div class="codehilite"><pre><span></span><span class="k">fn</span> <span class="nf">Path</span>::<span class="n">from_src</span><span class="p">(</span><span class="n">InFile</span><span class="o">&lt;</span><span class="n">path</span>: <span class="nc">ast</span>::<span class="n">Path</span><span class="o">&gt;</span><span class="p">)</span><span class="w"></span>
</pre></div>


<p>And then construct the hygiene inside this function instead ?</p>



<a name="183771609"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Path%3A%3Afrom_src/near/183771609" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Path.3A.3Afrom_src.html#183771609">(Dec 18 2019 at 17:35)</a>:</h4>
<p>you'd probably need the db to get from a <code>HirFileId</code> to the <code>Hygiene</code>?</p>



<a name="183772961"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Path%3A%3Afrom_src/near/183772961" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Path.3A.3Afrom_src.html#183772961">(Dec 18 2019 at 17:50)</a>:</h4>
<p>Oh... yes, we need it. :(</p>



<a name="183773351"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Path%3A%3Afrom_src/near/183773351" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Path.3A.3Afrom_src.html#183773351">(Dec 18 2019 at 17:54)</a>:</h4>
<p>Or can we change <code>Hygiene</code> such that it only store FileId instead ? And change <code>DollarCrate</code> to <code>DollarCrate(MacroFile)</code> ?</p>



<a name="183773883"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Path%3A%3Afrom_src/near/183773883" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Path.3A.3Afrom_src.html#183773883">(Dec 18 2019 at 18:00)</a>:</h4>
<p>OTOH,  right now<code>TypeRef::from_ast</code> are using <code>Path::from_ast</code> which is lack of Hygiene information. <br>
But passing <code>InFile&lt;ast::whatever&gt;</code> is much easier than passing a hygiene (or db) through the whole lowering infer-structure, right ?</p>



<a name="183790631"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Path%3A%3Afrom_src/near/183790631" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Path.3A.3Afrom_src.html#183790631">(Dec 18 2019 at 21:09)</a>:</h4>
<p><span class="user-mention" data-user-id="216201">@Edwin Cheng</span> this needs some design, but I imagine that, rather than having <code>Path::from_src</code>, we should have</p>
<div class="codehilite"><pre><span></span>struct LowerCtx {
    hygiene: Hygiene,
    db: DB, // not sure if really needed
    source_map // very much to be designed
}

impl LowerCtx {
  fn lower_path(ast: &amp;ast::Path) -&gt; hir::Path
  fn lower_type(ty: &amp;ast::TypeRef) -&gt; hir::TypeRef
}
</pre></div>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>